package algorithm.dynamicPlane;

/**
 * @author dengzhiyuan
 * @version 1.0
 * @describe
 * @time 2022/11/9 0:24
 */
public class HuiShu {
    private int maxW = 0;
    private int[] weight = {2, 2, 4, 6, 3};
    //物品个数
    private int n = 5;
    //背包承受重量
    private int w = 9;

    public void f(int i, int cw) {
        //cw == w表示裝滿  i==n表示物品都考察结束
        if (cw == w || i == n) {
            if (cw > maxW) {
                maxW = cw;
            }
            return;
        }
        //选择不装第i个物品
        f(i + 1, cw);
        if (cw + weight[i] <= w) {
            //选择装第i个物品
            f(i + 1, cw + weight[i]);
        }
    }

    public static void main(String[] args) {
        HuiShu huiShu = new HuiShu();
        huiShu.f(0,0);
        System.out.printf("maxW="+huiShu.maxW);
    }


}
